package com.course.controller;

import com.common.domain.pojo.Result;
import com.course.domain.pojo.CourseCategory;
import com.course.service.ICourseCategoryService;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/course/category")
public class CourseCategoryController {

    @Resource
    ICourseCategoryService iCourseCategoryService;

    @GetMapping("/list")
    @ApiOperation("获取课程分类列表")
    public Result<List<CourseCategory>> categorys() {
        List<CourseCategory> courses = iCourseCategoryService.list();
        return Result.success(courses);
    }

    @PostMapping("/add")
    @ApiOperation("新增课程分类")
    public Result<Boolean> addCategory(@RequestBody CourseCategory courseCategory) {
        boolean result = iCourseCategoryService.save(courseCategory);
        return Result.success(result);
    }

    @PostMapping("/update")
    @ApiOperation("更新课程分类")
    public Result<Boolean> updateCategory(@RequestBody CourseCategory courseCategory) {
        boolean result = iCourseCategoryService.updateById(courseCategory);
        return Result.success(result);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除课程分类")
    public Result<Boolean> deleteCategory(@PathVariable Long id) {
        boolean result = iCourseCategoryService.removeById(id);
        return Result.success(result);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("根据ID获取课程分类详情")
    public Result<CourseCategory> getCategoryById(@PathVariable Long id) {
        CourseCategory category = iCourseCategoryService.getById(id);
        return Result.success(category);
    }
}
